<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div{
            border:1px solid red;
        }
    </style>
</head>
<body>
    <div>

    </div>
    <input type="text" id="txt">
    <input type="button" value="add" onclick="doAdd()">
    <script>
        var arrs=JSON.parse(localStorage.getItem("arrs"));//将获取到的字符串转换数组
        var div=document.querySelector("div");
        for(var i=0;i<arrs.length;i++){
            var p=document.createElement("p");
            p.innerHTML=arrs[i];
            div.appendChild(p);
        }

        function doAdd(){
            var txt=document.getElementById("txt").value;//获取文本框的值
            arrs.push(txt);
            localStorage.setItem("arrs",JSON.stringify(arrs));//重新向localStorage中塞值
            var p=document.createElement("p");
            p.innerHTML=txt;
            div.appendChild(p);

        }

     
    </script>
</body>
</html>